--------------------------------------------------------
-- Baldy Bignose - A Moosader Compo 8 entry -          -
-- Code by Thomas Young                                -
-- Main Game Entrypoint                                -
--------------------------------------------------------
require 'gameobject.player'
require 'gamebase.map'

tplayer = player
tmap = Map
mode = "editor"

function love.load()
  
  love.graphics.setBackgroundColor(104, 136, 248) --set the background color to a nice blue
  if (mode == "game") then
	love.graphics.setMode(256, 224, false, true, 0) --set the window dimensions to 650 by 650
  else
	love.graphics.setMode(800, 600, false, true, 0)
  end
  
  tplayer:Init()
  tmap:Init(50,38,16, 'content/sprites/tiles.png')
end

function love.update(dt)
	tplayer:Update(dt)
	tmap:Update()
	
	love.keyboard.updateKeys()
	love.mouse.updatebuttons()
end

local function gameUpdate(dt)
  
end

function love.draw()
	--Draw some debug stuff
	tmap:Draw()
	tplayer:Draw()
	
	--GUI
	
	--Debug information
	love.graphics.print("Mouse Tile X: " .. tostring(math.floor(love.mouse.getX()/16)), 0, 0)
	love.graphics.print("Mouse Tile Y: " .. tostring(math.floor(love.mouse.getY()/16)), 0, 10)
	tmap:DrawEditorUI()
	
end

--code borrowed from http://www.yellow.indieis.me/2012/03/13/love2d-functions-to-check-if-key-was-pressedreleased/
--because I was too lazy to write all of this out myself :D

love.keyboard.keysPressed = { }
love.keyboard.keysReleased = { }

love.mouse.buttonPressed = { }
love.mouse.buttonReleased = { }

-- returns if specified key was pressed since the last update
function love.keyboard.wasPressed(key)
    if (love.keyboard.keysPressed[key]) then
        return true
    else
        return false
    end
end

-- returns if specified key was released since last update
function love.keyboard.wasReleased(key)
    if (love.keyboard.keysReleased[key]) then
        return true
    else
        return false
    end
end

-- concatenate this to existing love.keypressed callback, if any
function love.keypressed(key, unicode)
    love.keyboard.keysPressed[key] = true
end

-- concatenate this to existing love.keyreleased callback, if any
function love.keyreleased(key)
    love.keyboard.keysReleased[key] = true
end

-- call in end of each love.update to reset lists of pressed\released keys
function love.keyboard.updateKeys()
    love.keyboard.keysPressed = { }
    love.keyboard.keysReleased = { }
end

-- returns if specified button was pressed since the last update
function love.mouse.wasPressed(button)
    if (love.mouse.buttonPressed[button]) then
        return true
    else
        return false
    end
end

-- returns if specified button was released since last update
function love.mouse.wasReleased(button)
    if (love.mouse.buttonReleased[button]) then
        return true
    else
        return false
    end
end

-- concatenate this to existing love.buttonpressed callback, if any
function love.mousepressed(x,y,button)
    love.mouse.buttonPressed[button] = true
end

-- concatenate this to existing love.buttonreleased callback, if any
function love.mousereleased(x,y,button)
    love.mouse.buttonReleased[button] = true
end

-- call in end of each love.update to reset lists of pressed\released buttons
function love.mouse.updatebuttons()
    love.mouse.buttonPressed = { }
    love.mouse.buttonReleased = { }
end